package com.xmall.timer.controller;

import cn.hutool.json.JSONUtil;
import com.xmall.annotation.LoginRequiredFalse;
import com.xmall.define.base.Result;
import com.xmall.timer.service.ICommonTimerTaskService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 公共控制器
 */
@RequestMapping("/service/common/timerTask")
@RestController
public class CommonTimerTaskController {

    @Resource
    private ICommonTimerTaskService timerTaskService;

    /**
     * 执行任务
     */
    @LoginRequiredFalse
    @PostMapping("/executeOnce/{taskKey}")
    public Result executeOnce(@PathVariable("taskKey") String taskKey) {
        timerTaskService.executeOnce(taskKey);
        return Result.success();
    }

    /**
     * 任务列表
     */
    @LoginRequiredFalse
    @GetMapping("/taskList")
    public Result<String> taskList() {
        return Result.success(JSONUtil.toJsonStr(timerTaskService.taskList()));
    }

}
